package com.ricky.handler.authorise;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

import com.ricky.core.net.abs.Request;
import com.ricky.core.net.msg.Context;
import com.ricky.core.net.utils.Attributes;
import com.ricky.db.bll.HeroBll;
import com.ricky.db.model.HeroData;
import com.ricky.game.GameWorld;
import com.ricky.game.Hero;
import com.ricky.game.MsgHelper;
import com.ricky.game.scene.SceneController;
import com.ricky.handler.IHandler;

/**
 * 链接
 * 
 * @author rik
 * 
 */
public class Connect implements IHandler {

	protected static Logger log = Logger.getLogger(Connect.class);

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void proccess(Request request,  Map<String,Object>  context) {
		Map reqData = (Map) context;

		String userName = reqData.get("name").toString();

		// 从数据库查询用户关联的英雄
//		HeroData hd = HeroBll.SelectHeroByUser(userName);
//		if (hd == null) // 如果没有关联的英雄
		{
			request.setAttribute(Attributes.USER_Name, userName);// 设置玩家名
			Map create = new HashMap();
			create.put("cmd", "showLogin");//显示登陆界面
			MsgHelper.sendMsg(request, create);
		} 
//		else 
//		{
//			request.setAttribute(Attributes.USER_Name, userName);// 设置玩家名
//			Hero h = new Hero();
//			HeroData.copyTo(hd, h);
//
//			request.isValidate(true);
//			request.setAttribute(Attributes.HERO, h);
//			GameWorld.getInstance().joinWorld(h, request);
//			
//			Map msg=new HashMap();
//			msg.put("cmd", "l.setHero");
//			msg.put("hero", h);
//			MsgHelper.sendMsg(h.getName(), msg);
//		}

		log.info("收到链接消息，选择英雄");
	}

}
